const app = getApp();
Page({
  data: {
    loading:true,
    showbar:false,
    config: {},
    list: [],
    today: 0,
    page: 0,
    active:0
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    app.isLogin(()=>{
      this.getList();
    });
    this.setData({
      config:app.globalData.appConfig
    })
  },
  //下拉刷新
  onPullDownRefresh: function () {
    wx.showNavigationBarLoading();
    setTimeout(()=>{
      wx.hideNavigationBarLoading();
      wx.stopPullDownRefresh();
    },1500);
    this.setData({
      loading: true,
      page:0,
      list:[]
    });
    this.getList();
  },
  //上拉加载更多
  onReachBottom: function () {
    this.setData({
      loading: true,
    }); 
    this.getList();
  },
  /**
   * 点击切换
   */
  onChange(event) {
    this.setData({
      loading: true,
      page: 0,
      list: [],
      today: event.detail.name
    });
    this.getList();
  },
  /**
   * 账单
   */
  getList: function () {
    if (this.data.loading) {
      var param = {
        page: this.data.page + 1,
        today: this.data.today
      }
      app.api().Get("api/v1/smartbc/user/bill",param,(result) => {
        if (result.code == 200) {
          var list = this.data.list;
          for (let i in result.data) {
            list.push(result.data[i]);
          }
          this.setData({
            list: list,
            page: param.page,
          });
        }
      })
      this.setData({
        loading: false,
      });
    }
  },
  //滚动
  onPageScroll(res){
    let scrollTop = res.scrollTop;
    this.setData({
      showbar: 110 <= scrollTop ?true :false
    })
  }
})